2023/12/231864字符
npm
基础命令
npm config ls -l // 查看 npm 配置
npm config set cache "D:\web\npm\node_cache" // 配置 npm 环境变量地址
npm config set prefix "D:\web\npm\node_global" // 配置全局包下载地址
npm config get prefix // 查看 npm 地址
npm list -g // 查看全局依赖 --depth(限制输出模块层级)
npm root -g // 查看全局包地址
npm config get registry // https://registry.npmjs.org/ npm官方下载地址
npm config set registry https://registry.npmmirror.com/ // 更改地址到淘宝镜像
下载
npm install jquery // 安装包 'i'
npm uninstall jquery // 卸载包 'un/r' 用不到的包也会被卸载
npm install jquery -E // 安装配置规定版本
npm install jquery@2.1.0 // 安装指定版本
npm view jquery // 查询包信息 'v'
npm view jquery versions // 所有版本号
更新
npm outdated // 查看需要更新的包
npm update
npm i -g npm // 更新 npm
依赖关系
npm list // 查看依赖关系
npm list --depth=0 // 只查看第一层依赖关系
配置文件 | 还原包
npm init --yes // 生成默认配置文件
npm install // 根据配置文件还原 node_modules
npm install --production // 仅还原生产环境依赖
运行
npm run // 运行模块程序
npm run open // 运行自定义脚本,可在 package.json scripts 中配置
node index.js // 运行脚本文件
Linux 安装
wget https://nodejs.org/dist/v10.16.0/node-v10.16.0-linux-x64.tar.xz # 下载
tar xf node-v10.16.0-linux-x64.tar.xz # 解压
vim /etc/profile # 添加配置 export PATH=$PATH:/root/node-v10.16.0-linux-x64/bin
source /etc/profile
node -v # 检查版本